import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/r.dart';
import 'notice_view.dart';

class NoticeWidget extends StatelessWidget {
  final int noReadCount;
  const NoticeWidget({
    Key key,
    @required this.noReadCount,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10),
      child: Stack(
        children: [
          noticeItemWidget(context),
          Positioned(
            top: (kToolbarHeight - 22) / 2 - 5,
            right: 5,
            child: dot(noReadCount),
          ),
        ],
      ),
    );
  }

  Widget noticeItemWidget(BuildContext context) {
    return InkWell(
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 10),
        alignment: Alignment.center,
        child: Image.asset(R.assetsCommonNotice, height: 20),
      ),
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (cxt) => NoticeView(),
          ),
        );
      },
    );
  }

  Widget dot(int count) {
    return Container(
      height: 5,
      width: 5,
      decoration: BoxDecoration(
        color: count > 0 ? Color.fromRGBO(255, 74, 82, 1) : Colors.transparent,
        shape: BoxShape.circle,
      ),
    );
  }
}
